<?php

namespace App\Http\Controllers\Api\V1;

use App\Models\File;
use App\Models\Version;

class VersionController extends BaseController
{
    public function index()
    {
        /*
        $this->validate($request, [
            'device_code' => 'required|string|exists:devices,code',
        ], [], []);
*/
        $version = Version::orderBy("id", "desc")->select("version", "hash", "is_force", "is_whole")->first();
        $data = ['version'=>"1.0.0",
            'hash'=>'',
            'is_whole'=>1,
            'is_force'=>0,
            'path'=>'',
            'part_path'=>'',
            ];

        if (!empty($version)){
            $data['version'] = $version->version;
            $data['hash'] = $version->hash;
            $data['is_force'] = $version->is_force;
            $data['is_whole'] = $version->is_whole;
            $data['path'] = File::getFileUrl($version->hash);
            $version->is_whole == 0 && $data['part_path'] = asset("storage/". config("site.version_path"));
            //return $this->json($data);
        }

            return $this->json($data);

    }
}
